﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//................
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//.................
namespace QLKTX1._0.DAO
{
    class NhomQuyenDAO
    {
        public static List<NhomQuyenDTO> dsNhomQuyen()
        {
            List<NhomQuyenDTO >dsNhomQuyen = new List<NhomQuyenDTO> ();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM NhomQuyen");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                NhomQuyenDTO nq = new NhomQuyenDTO();
                nq.MaNhomQuyen = Int32.Parse(dt.Rows[i]["maNhomQuyen"].ToString());
                nq.TenNhomQuyen = dt.Rows[i]["tenNhomQuyen"].ToString();
                nq.MoTaNQ = dt.Rows[i]["moTaNQ"].ToString();

                dsNhomQuyen.Add (nq);
                
            }

            return dsNhomQuyen;
        }
        //Ham Insert
        public static bool themNhomQuyen(NhomQuyenDTO nq)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO NhomQuyen(maNhomQuyen,tenNhomQuyen,moTaNQ) VALUES(" + nq.MaNhomQuyen  + ",'" + nq.TenNhomQuyen  + "','"+nq.MoTaNQ +"')");

        }
        //Ham Delete
        public static bool xoaNhomQuyen(NhomQuyenDTO nq)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM NhomQuyen WHERE maNhomQuyen='" + nq.MaNhomQuyen + "'");
        }
        //Ham Update
        public static bool capNhatNhomQuyen(NhomQuyenDTO nq)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE NhomQuyen set tenNhomQuyen='" + nq.TenNhomQuyen + "', moTaNQ= '" + nq.MoTaNQ + "'  WHERE maNhomQuyen='" + nq.MaNhomQuyen + "'");
        }
    
    }
}
